#include <cstdio>
#include <cstring>

struct Node
{
    Node *next[ 26 ], *fail;
    int flag;
    Node( ) { flag = 0; memset( next, 0, sizeof( next ) ); }
}*head, *q[ 500000 ];

void insert( Node *head, char *s )
{
    Node *p = head;
    int i = 0;
    while ( s[ i ] )
    {
        if ( !p->next[ s[ i ] - 'a' ] ) p->next[ s[ i ] - 'a' ] = new Node;
        p = p->next[ s[ i ] - 'a' ];
        i++;
    }
    p->flag++;
}

void build_ac( Node *head )
{
    Node *p, *s;
    int i, front = 0, tail = 0;
    head->fail = head;
    q[ tail++ ] = head;
    while ( tail > front )
    {
        p = q[ front++ ];
        for ( i = 0; i < 26; i++ )
            if ( p->next[ i ] )
            {
                s = p->fail;
                while ( s != head && !s->next[ i ] ) s = s->fail;
                if ( s->next[ i ] && s->next[ i ] != p->next[ i ] )
                    p->next[ i ]->fail = s->next[ i ];
                else
                    p->next[ i ]->fail = s;
                q[ tail++ ] = p->next[ i ];
            }
    }
}

char str[ 1000001 ];

int calc( Node *head, char *s )
{
    Node *p = head, *t;
    int i = 0, ret = 0;
    while ( s[ i ] )
    {
        while ( !p->next[ s[ i ] - 'a' ] && p != head ) p = p->fail;
        if ( p->next[ s[ i ] - 'a' ] ) p = p->next[ s[ i ] - 'a' ];
        t = p;
        while ( t->flag != -1 ) { ret += t->flag; t->flag = -1; t = t->fail; }
        i++;
    }
    return ret;
}

int main( )
{
    int t, n;
    char s[ 60 ];
    scanf("%d", &t);
    while ( t-- )
    {
        head = new Node;
        scanf("%d", &n);
        gets( s );
        while ( n-- )
        {
            gets( s );
            insert( head, s );
        }
        build_ac( head );
        gets( str );
        printf("%d\n", calc( head, str ));
    }
    return 0;
}
